#pragma once
#include "Texture.h"
#include "NeroEngine\NResource.h"
#include "Common.h"

namespace Graphics
{
	class Material;
	class Buffer;
}

namespace Graphics
{
#ifdef DX_11
class Model : public Engine::NResource
{
private:
	RTTI_DECLARATIONS(Model, Engine::NResource)

public:
	typedef std::list<std::string> TextureList;

private:
	private:
	struct VertexType
	{
		D3DXVECTOR3 Position;
		D3DXVECTOR4 Color;
		D3DXVECTOR2 Texture;
		D3DXVECTOR3 Normal;
	};

	struct ModelType
	{
		float X, Y, Z;
		float Tu, Tv;
		float Nx, Ny, Nz;
	};

	struct InstanceType
	{
		D3DXVECTOR3 position;
	};

public:
	Model(const std::string& instanceName, const std::string& filePath);

	virtual ~Model(void);

	virtual bool Initialize();

	virtual void Dinititalize();

	virtual void Render();

	virtual void Update(float deltaTime);

	int GetIndexCount() const;

	int GetVertexCount() const;

	int GetInstanceCount() const;

	TextureArray* GetTextures();

	Texture* GetTexture(int index = 0);
	
	void SetTexture(Texture* texture);

	bool LoadTexture(const char* textureName);

	bool LoadModel(const char* modelName);

	void ReleaseTexture();

	void ReleaseModel();

private:
	bool InitializeBuffers();

	void DeinitializeBuffers();

	void RenderBuffers();

private:
	Buffer* mVertexBuffer; 
	Buffer* mIndexBuffer;
	Buffer* mInstanceBuffer;
	int mVertexCount;
	int mIndexCount;
	int mInstanceCount;
	TextureArray* mTextures;
	ModelType* mModel;
};

#elif defined(DX_9)
class Model : public Engine::NResource
{
	RTTI_DECLARATIONS(Model, Engine::NResource)
public:
	Model();
	Model(const std::string& instanceName, const std::string& filePath);
	virtual ~Model(void);
	virtual void Initialize();
	virtual void Dinititalize();
	virtual void Update(float gameTime);
	virtual void Render();
	LPD3DXMESH GetMesh();
	DWORD GetMaterialCount();
	Texture* GetTexture();
	void SetTexture(Texture* texture);
	int GetIndexCount() const;
	int GetVertexCount() const;
	
protected:	
	void Load(const std::string& filePath);

protected:
	LPD3DXMESH mMesh;
	D3DMATERIAL9* mMaterials;			//!<
	std::vector<Texture*> mTextures;
	DWORD mMaterialCount;
	int mVertexCount;
	int mIndexCount;
};
#endif
}